package com.littleHan.brushQuestions.web.start.service.impl;

import com.littleHan.brushQuestions.web.start.dao.GeneralUserDao;
import com.littleHan.brushQuestions.web.start.dao.RoleDao;
import com.littleHan.brushQuestions.web.start.dao.UserRoleDao;
import com.littleHan.brushQuestions.web.start.dao.UserDao;
import com.littleHan.brushQuestions.web.start.pojo.GeneralUser;
import com.littleHan.brushQuestions.web.start.pojo.Role;
import com.littleHan.brushQuestions.web.start.pojo.User;
import com.littleHan.brushQuestions.web.start.pojo.UserRole;
import com.littleHan.brushQuestions.web.start.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoleServiceImpl implements RoleService {

    @Autowired
    private UserRoleDao userRoleDao;

    @Autowired
    private GeneralUserDao generalUserDao;

    @Autowired
    private UserDao userDao;

    @Autowired
    private RoleDao roleDao;

    @Override
    public List<Role> getRolesByUsername(String username) {
        //用username去普通用户表里取出其id
        GeneralUser generalUser=generalUserDao.getGeneralUserByUsername(username);
        //根据普通用户表的id，去用户表取出id
        User user=userDao.getUserByGeneralUserId(generalUser.getId());
        //根据userId去role表获取角色
        List<UserRole>userRoleList=userRoleDao.getRoleByUserId(user.getId());
        System.out.println(userRoleList);
        //根据取得的roleId去role表里获得角色信息
        List<Role> roleList=roleDao.getRoleById(userRoleList);
        return roleList;
    }
}
